//
//  HomeListTableViewCell.m
//  PaiLeXiongProject
//
//  Created by 小獾科技 on 2017/8/22.
//  Copyright © 2017年 小獾科技. All rights reserved.
//

#import "HomeListTableViewCell.h"

@interface HomeListTableViewCell ()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *titleLabel;//商品名称
@property (nonatomic, strong) UILabel *introduceLabel;// 商品介绍
@property (nonatomic, strong) UILabel *commentLabel;//评论
@property (nonatomic, strong) UILabel *currentPriceLabel;//现价
@property (nonatomic, strong) UILabel *originalPriceLabel;//原价
@property (nonatomic, strong) UIImageView *starImage;//星星评论

@end

@implementation HomeListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        _imgView = [UIImageView new];
        _imgView.image = IMAGE(@"home_list_hold");
        _imgView.backgroundColor = ColorGreen;
        [self addSubview:_imgView];
        [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.left.equalTo(self).offset(10);
            make.right.equalTo(self).offset(-10);
            make.height.equalTo(@174);
        }];
        
        _titleLabel = [UILabel new];
        _titleLabel.text = @"爱儿美儿童摄影（洋桥店）";
        _titleLabel.textColor = ColorFrom16(0x323232);
        _titleLabel.font = PFRFONT(16);
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_imgView.mas_bottom).offset(22);
            make.left.equalTo(self).offset(10);
            make.right.equalTo(self);
            make.height.equalTo(@18);
        }];
        
        _introduceLabel = [UILabel new];
        _introduceLabel.text = @"洋桥/木樨园 2.3km";
        _introduceLabel.textColor = ColorFrom16(0x7f7e7d);
        _introduceLabel.font = PFRFONT(16);
        [self addSubview:_introduceLabel];
        [_introduceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleLabel.mas_bottom).offset(12);
            make.left.equalTo(self).offset(10);
            make.width.greaterThanOrEqualTo(@80);
            make.height.equalTo(@18);
        }];
        
        _commentLabel = [UILabel new];
        _commentLabel.text = @"835条评论";
        _commentLabel.textColor = ColorFrom16(0x999999);
        _commentLabel.font = PFRFONT(14);
        [self addSubview:_commentLabel];
        [_commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleLabel.mas_bottom).offset(14);
            make.left.equalTo(_introduceLabel.mas_right).offset(11);
            make.width.equalTo(@72);
            make.height.equalTo(@16);
        }];
        
        _currentPriceLabel = [UILabel new];
        _currentPriceLabel.text = @"￥580";
        _currentPriceLabel.textColor = ColorFrom16(0xff5b7a);
        _currentPriceLabel.font = PFMFONT(18);
        [self addSubview:_currentPriceLabel];
        [_currentPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_commentLabel.mas_bottom).offset(11);
            make.left.equalTo(self).offset(10);
//            make.width.equalTo(@60);
            make.height.equalTo(@20);
        }];
        
        _originalPriceLabel = [UILabel new];
        _originalPriceLabel.text = @"￥620";
        _originalPriceLabel.textColor = ColorFrom16(0x999999);
        _originalPriceLabel.font = PFMFONT(14);
        [self addSubview:_originalPriceLabel];
        [_originalPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_commentLabel.mas_bottom).offset(13);
            make.left.equalTo(_currentPriceLabel.mas_right).offset(10);
//            make.width.equalTo(@48);
            make.height.equalTo(@16);
        }];
        
//        _starImage = [UIImageView new];
//        _starImage.backgroundColor = ColorRed;
//        _starImage.image = IMAGE(@"");
//        [self addSubview:_starImage];
//        [_starImage mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(_commentLabel.mas_bottom).offset(15);
//            make.left.equalTo(_originalPriceLabel.mas_right).offset(18);
//            make.width.equalTo(@60);
//            make.height.equalTo(@14);
//        }];
        
        _goToPay = [UIButton buttonWithType:UIButtonTypeCustom];
        [_goToPay setTitle:@"立即购买" forState:0];
        [_goToPay setTitleColor:ColorFrom16(0xffffff) forState:0];
        _goToPay.layer.backgroundColor = ColorFrom16(0xff5b7a).CGColor;
        _goToPay.layer.cornerRadius = 5;
        _goToPay.titleLabel.font = PFRFONT(16);
        [self addSubview:_goToPay];
        [_goToPay mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_commentLabel.mas_bottom).offset(4);
            make.right.equalTo(self).offset(-10);
            make.width.equalTo(@94);
            make.height.equalTo(@40);
        }];
        
        
    }
    return self;
}

- (void)configWithModel:(HomeListModel *)model
{
    [_imgView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:IMAGE(@"home_list_hold")];
    _titleLabel.text = model.goods_name;
    _introduceLabel.text = model.addr;
    _currentPriceLabel.text = [NSString stringWithFormat:@"￥%@", model.sale_price];
    _originalPriceLabel.text = [NSString stringWithFormat:@"￥%@", model.goods_price];
    _commentLabel.text = [NSString stringWithFormat:@"%@条点评", model.goods_grade];
    
    NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleThick]};
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:_originalPriceLabel.text attributes:attribtDic];
    _originalPriceLabel.attributedText = string;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
